package com.coder.oj.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.coder.oj.common.core.BaseContext;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

public class DataMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		this.strictInsertFill(metaObject, "createBy", Long.class, BaseContext.getCurrentId());
		this.strictInsertFill(metaObject, "updateBy", Long.class, BaseContext.getCurrentId());
		this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
		this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		this.strictInsertFill(metaObject, "updateBy", Long.class, BaseContext.getCurrentId());
		this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
	}
}
